package cn.xydpeng.springframework.aop.framework;

import cn.xydpeng.springframework.util.Assert;
import cn.xydpeng.springframework.util.ClassUtils;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/22
 * @description:
 */
public class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializable {
    /**
     * Config used to configure this proxy.
     */
    private final AdvisedSupport advised;

    private final Class<?>[] proxiedInterfaces;
    /**
     * Is the {@link #equals} method defined on the proxied interfaces?
     */
    private boolean equalsDefined;
    /**
     * Is the {@link #hashCode} method defined on the proxied interfaces?
     */
    private boolean hashCodeDefined;

    public JdkDynamicAopProxy(AdvisedSupport advised) {
        Assert.notNull(advised, "AdvisedSupport must not be null");
        this.advised = advised;
        this.proxiedInterfaces = null;
    }

    @Override
    public Object getProxy() {
        return getProxy(ClassUtils.getDefaultClassLoader());
    }

    @Override
    public Object getProxy(ClassLoader classLoader) {
        return Proxy.newProxyInstance(classLoader, proxiedInterfaces,this);
    }

    @Override
    public Class<?> getProxyClass(ClassLoader classLoader) {
        return Proxy.getProxyClass(classLoader, this.proxiedInterfaces);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //TODO
        return null;
    }
}
